<!--
 * @Author: your name
 * @Date: 2022-03-29 16:55:55
 * @LastEditTime: 2022-03-29 17:05:53
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\继承方式2借用构造函数继承220329.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>借用构造函数继承</title>
</head>

<body>
  <script>
    //使用父类的构造函数来增强子类实例，等同于复制父类的实例给子类（不使用原型）
    //只能继承父类的实例属性和方法，不能继承原型属性/方法 无法实现复用，每个子类都有父类实例函数的副本，影响性能

    function father() {
      this.color = ["red", "green", "blue"];
    }

    function son() {
      //继承自father
      father.call(this);
    }
    var instance1 = new son();
    instance1.color.push("black");
    console.log(instance1.color); //"red,green,blue,black"

    var instance2 = new son();
    console.log(instance2.color);//"red,green,blue"
  </script>
</body>

</html>